package cn.liujianbo.example.pattern.chain_of_responsibility;

import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.List;

/**
 * @author 刘建波
 * @date 2022-01-18 23:06
 */
@Getter
@Setter
public class HandlerChain extends AbstractHandler{
    private List<AbstractHandler> chain;

    @Override
    public void doFilter() {
        System.out.println("责任链~");
        chain.get(0).filter();
    }

    public static void main(String[] args) {
        HandlerChain chain = new HandlerChain();
        Handler1 handler1 = new Handler1();
        Handler2 handler2 = new Handler2();
        Handler3 handler3 = new Handler3();
        handler1.setNextHandler(handler2);
        handler2.setNextHandler(handler3);
        chain.setChain(Arrays.asList(handler1, handler2, handler3));
        chain.filter();
    }
}
